//
//  BZThemeDatasource.m
//  MZBasic
//
//  Created by Better on 2022/9/17.
//

#import "BZThemeDatasource.h"

@implementation BZThemeDatasource
- (nonnull NSDictionary *)themeExampleJson {
    NSFileManager *filemanager = [NSFileManager defaultManager];
    NSString *fullThemePath = [ThemeDownload upZipPath:self.themeModel.path];
    NSString *plistPath = [NSString stringWithFormat:@"%@/theme.plist",fullThemePath];
    NSDictionary *dic;
    BOOL isExists = [filemanager fileExistsAtPath:plistPath];
    if (isExists) {
       NSDictionary *themePlist = [NSDictionary dictionaryWithContentsOfFile:plistPath];
        dic = themePlist[@"color"];
    }
    //没有的情况要给默认
    return dic;
}

- (NSString *)themeImagePath {
    NSString *imageFilePath = [ThemeDownload upZipPath:self.themeModel.path];;
    return imageFilePath;
}

- (NSDictionary *)themeVersion {
    return @{@"version":@"default"};
}

- (id<BZThemeExampleProtocol>) initThemeWithThemeVersion:(NSDictionary *) themeVersion {
    BZThemeDatasource *theme = [[BZThemeDatasource alloc] init];
    if ([ThemeDownConfigModel isShowFestivalTheme] && [ThemeDownConfigModel festivalThemeAndOprationTheme]) {
        theme.themeModel = [ThemeDownConfigModel readCurrentNormalTheme];
    }else{
        if([ThemeDownConfigModel isShowFestivalTheme]){
            theme.themeModel = [ThemeDownConfigModel festivalTheme];
        }else{
            theme.themeModel = [ThemeDownConfigModel readCurrentNormalTheme];
        }
        
    }
    
    if (!theme.themeModel) {
        BZThemeDefaultExample *themDefault = [[BZThemeDefaultExample alloc]init];
        return themDefault;
    }
    return theme;

}
@end
